using System;
using System.Linq;
using System.Collections.Generic;

using DemoApp.DataAccess;

using EntModApp.EntServices.Business;
using EntModApp.EntServices.Data;

namespace DemoApp.BusinessLayer 
{
  public partial class UserObjectRepository : 
    IUserObjectRepository 
  {
    public IBusinessObjectCollection<IUser> RetrieveAll()
    {
      var query = new UserLoadSettings();
      return Retrieve(query);
    }

    public IBusinessObjectCollection<IUser> Retrieve(UserLoadSettings query)
    {
      query = UserLoadSettings.FromUserLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaUserInfoCollection.GetUserInfoCollection(query);
        return result;
      }
      else
      {
        var result = CslaUserEditCollection.GetUserEditCollection(query);
        return result;
      }
    }

    public IUser RetrieveOne(UserLoadSettings query)
    {
      query = UserLoadSettings.FromUserLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaUserInfoCollection.GetUserInfoCollection(query);
        return result.FirstOrDefault<IUser>();
      }
      else
      {
        var result = CslaUserEditCollection.GetUserEditCollection(query);
        return result.FirstOrDefault<IUser>();
      }
    }

    public int Count()
    {
      return Count(null);
    }

    public int Count(UserLoadSettings query)
    {
      query = UserLoadSettings.FromUserLoadSettings(query);
      return CslaUserInfoCollection.GetCount(query);
    }

    public IUser New()
    {
      return CslaUserEdit.New();
    }

    public void Save(IBusinessObjectCollection<IUser> collection)
    {
      throw new NotImplementedException();
    }

    public void Save(IUser obj)
    {
      throw new NotImplementedException();
    }
  }
}
